package com.anos.demoinserticon;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.util.ArrayList;

/**
 * Created by Admin on 4/1/2014.
 */
public class ListIconAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Bitmap> mListIcon;

    public ListIconAdapter(Context context, ArrayList<Bitmap> data) {
        super();
        mContext = context;
        mListIcon = data;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return mListIcon.size();
    }

    @Override
    public Object getItem(int position) {
        return mListIcon.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new AbsListView.LayoutParams(45,
                    45));
        } else {
            imageView = (ImageView) convertView;
        }
        imageView.setImageBitmap(mListIcon.get(position));

        return imageView;
    }
}
